import _root_.sbt.Keys._
import _root_.sbt._
import com.thoughtworks.sbtApiMappings.ApiMappings
import play.routes.compiler.InjectedRoutesGenerator
import play.sbt.Play.autoImport._
import play.sbt.PlayScala
import play.sbt.routes.RoutesKeys
import play.twirl.sbt.Import.TwirlKeys

object Build extends Build {
  final val DependsConfigure = "test->test;compile->compile"

  import BuildSettings._
  import Dependencies._

  override lazy val settings = super.settings :+ {
    shellPrompt := (s => Project.extract(s).currentProject.id + " > ")
  }

  ///////////////////////////////////////////////////////////////
  // Activity project
  ///////////////////////////////////////////////////////////////
  lazy val activity = Project("social-credits-activity-service", file("."))
    .enablePlugins(PlayScala)
    .enablePlugins(ApiMappings)
    .aggregate(psPlatform, psUtil, psData)
    .dependsOn(psPlatform % DependsConfigure, psData % DependsConfigure, psUtil % DependsConfigure)
    .settings(basicSettings: _*)
    .settings(
      description := "social-credits-activity-service",
      PlayKeys.playDefaultPort := 9001,
      TwirlKeys.templateImports ++= Seq("cn.socialcredits.activity.data.model._", "cn.socialcredits.activity.data.domain._"),
      RoutesKeys.routesGenerator := InjectedRoutesGenerator,
      libraryDependencies ++= (
        __compile(_scala) ++
          __compile(_scalaModules) ++
          __compile(_scalaLogging) ++
          __compile(_commonCodecs) ++
          __compile(_commonsLang3) ++
          __compile(_slf4j) ++
          __compile(_logback) ++
          __test(_scalatestPlay)),
      libraryDependencies ~= {
        _ map {
          case m if m.organization == "com.typesafe.play" =>
            m.exclude("commons-logging", "commons-logging").
              exclude("com.typesafe.akka", "akka-actor").
              exclude("com.typesafe.akka", "akka-slf4j").
              exclude("org.scala-lang", "scala-library").
              exclude("org.scala-lang", "scala-compiler").
              exclude("org.scala-lang", "scala-reflect").
              exclude("org.scala-lang.modules", "scala-xml").
              exclude("org.scala-lang.modules", "scala-parser-combinators").
              excludeAll()
          case m => m
        }
      })

  ///////////////////////////////////////////////////////////////
  // projects
  ///////////////////////////////////////////////////////////////
  lazy val psPlatform = Project("platform", file("platform"))
    .enablePlugins(ApiMappings)
    .dependsOn(psData % DependsConfigure, psUtil % DependsConfigure)
    .settings(basicSettings: _*)
    .settings(
      description := "platform",
      scalacOptions ++= Seq("-Ywarn-unused-import",
        "-Ywarn-unused"),
      libraryDependencies ++= (
        __compile(_commonsEmail) ++
          __provided(_play)))

  lazy val psData = Project("data", file("data"))
    .enablePlugins(ApiMappings)
    .dependsOn(psUtil % DependsConfigure)
    .settings(basicSettings: _*)
    .settings(
      description := "data",
      scalacOptions ++= Seq("-Ywarn-unused-import",
        "-Ywarn-unused"),
      libraryDependencies ++= (
        __provided(_commonCodecs) ++
          __provided(_commonsLang3) ++
          __provided(_play) ++
          __provided(_playJson) ++
          __compile(_reactivemongo)))

  lazy val psUtil = Project("util", file("util"))
    .enablePlugins(ApiMappings)
    .settings(basicSettings: _*)
    .settings(
      description := "util",
      scalacOptions ++= Seq("-Ywarn-unused-import",
        "-Ywarn-unused"),
      libraryDependencies ++= (
        __provided(_playJson) ++
          __provided(_reactivemongo) ++
          __provided(_commonsEmail) ++
          __provided(_commonCodecs) ++
          __provided(_commonsLang3)))

}

